package D240422;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;

public class JsoupDemo03 {
    public static void main(String[] args) throws IOException {
        Document doc = Jsoup.connect("https://bbs2.xmfish.com/thread-htm-fid-55-search-all-orderway-postdate-asc-DESC-page-1.html").get();
        Elements elements = doc.getElementsByClass("subject_t");
        // 输出所有标题和地址
        /*for (int i = 0; i < elements.size(); i++) {
            System.out.println("标题：" + elements.get(i).text());
            System.out.println("网址：https://bbs2.xmfish.com/"+elements.get(i).attr("href"));
        }*/
        // 输出含有关键字电动的标题和网址
        for (int i = 0; i < elements.size(); i++) {
            if (elements.get(i).text().contains("电动")) {
                System.out.println("标题：" + elements.get(i).text());
                System.out.println("网址：https://bbs2.xmfish.com/" + elements.get(i).attr("href"));
            }
        }
    }
}
